package com.ringtheweb.common.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Security utility functions.
 * @author ldewavri
 *
 */

public class SecurityUtils {
	
    private static String DEFAULT_ALGORITH = "SHA-256";
    
    public static String hashPassword(byte[] passwordBytes) 
    throws NoSuchAlgorithmException {
        MessageDigest digest = MessageDigest.getInstance(DEFAULT_ALGORITH);
        byte[] hashBytes = digest.digest(passwordBytes);
        String hashString = Base64.encodeBytes(hashBytes);
        return hashString;
    }
    
    public static boolean verifyPassword(byte[] passwordBytes, String hashString) 
    throws NoSuchAlgorithmException {
        return hashPassword(passwordBytes).equals(hashString);
    }
}
